<?php

class PasswordController {
	private static $passed = false;
	const PASSPHRASE = 'passphrase';
	const REPLACE_CALLED_FUNC = '###curCalledFunction###';

	public static function getMainWindow ()  {
		
		$passphrase = self::getPassphrase();

		if (empty($passphrase))  {
			if (empty($_POST['passwordRequest']))  {
				$data = PasswordModel::getPasswordRequestData();
		
				$data = ArrayProcessor_ArrayProcessor::replaceValue($data, 'index.php?id=17&function=1&password=false', self::REPLACE_CALLED_FUNC);
		
				PasswordView::passwordRequest($data);
			}
			else  {
				$passed = self::verifyPassword($_POST['passwordRequest']);
				if (!self::$passed)  {
					$_POST['passwordRequest'] = '';
					self::getMainWindow();
				}
			}
		}
		else  {
			$passed = self::verifyPassword($passphrase);
			if (!self::$passed)  {
				$data[self::PASSPHRASE] = null;
				MainController::storeSessionData($data);
				self::getMainWindow();
			}
		}
	}
	
	private static function verifyPassword ($password)  {
		//sha1 representation for kircheum6-18
		$a = 'bafb40a38d51e308f5a8d5e012a9e30ad5e4a8dc';
		
		if (sha1($password) == $a)  {
			self::$passed = true;
			$data[self::PASSPHRASE] = $password;
			MainController::storeSessionData($data);
		}
	}
	
	public static function getPassed ()  {
		return self::$passed;
	}
	
	public static function getPassphrase ()  {
		return MainController::getSessionData(self::PASSPHRASE);
	}

	
}